// 导入express
const express = require('express')
const path = require('path')

// 创建路由对象
const router = express.Router()

// 导入中间件
const {checkLogin} = require(path.join(__dirname,"middleware"))

// 导入相关控制器
const home = require(path.join(__dirname,"controllers/home"))
const account = require(path.join(__dirname,"controllers/account"))
const list = require(path.join(__dirname,"controllers/list"))
const item = require(path.join(__dirname,"controllers/item"))
const cart = require(path.join(__dirname,"controllers/cart"))
const member = require(path.join(__dirname,"controllers/member"))
const order = require(path.join(__dirname,"controllers/order"))
const pay = require(path.join(__dirname,"controllers/pay"))

// 处理首页请求
router.get('/',home.index)
router.get('/likes',home.getLikes)

// 处理账号请求
router.get('/login',account.getLoginPage)
router.post('/login',account.login)

// 处理商品的请求
// 商品列表
router.get('/list/:cateId',list.index)
// 商品搜索
router.get('/search',list.search)
// 商品详情
router.get('/item/:goodsId',item.index)

// 处理购物车请求
router.get('/cart/add',cart.add)
router.get('/cart/success',cart.addSuccess)
router.get('/cart',cart.index) 
router.get('/cart/find',cart.find) //json
router.post('/cart/edit',cart.edit) //json
router.post('/cart/delete',cart.delete) //json

// 个人中心 & 订单
router.get('/member',checkLogin,member.index) 
router.get('/order/create',checkLogin,order.create)
router.get('/order',checkLogin,order.index)
router.get('/order/all',checkLogin,order.all)
router.get('/order/delete',checkLogin,order.delete)

// 支付
router.get('/pay',checkLogin,pay.payOrder)
router.get('/pay/success',checkLogin,pay.success)


// 导出路由
module.exports = router